﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;
using FubiManger.Pad;
using FubiManger.Staff;
using FubiManger.Settlement;
using FubiManger.Logistics;
using FubiManger.Kitchen;
namespace FubiManger.UI
{
    partial class LoginForm : Smobiler.Core.Controls.MobileForm
    {
        public LoginForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        /// <summary>
        /// 商户ID
        /// </summary>
        public string merchantid { get; set; }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnlogin_Press(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtaccout.Text))
            {
                Toast("请填写账号");
            }
            else if (string.IsNullOrEmpty(txtpwd.Text))
            {
                Toast("请填写密码");
            }
            else
            {
                string str = AesUtil.DecryptString("uq02EqWSqcZbz3dF6ZS1ug==");
                string pwd = AesUtil.EncryptString(txtpwd.Text);
                ms_admins admins = merchantDal.Login(txtaccout.Text, pwd);
                if (!string.IsNullOrEmpty(admins.id))
                {
                    if (admins.status == "1")
                    {
                        this.Form.LoadClientData("merchantid", admins.merchant_id);
                        this.Form.LoadClientData("adminid", admins.id);
                        switch (admins.admintype)
                        {
                            case "1":

                                MainForm mfrm = new MainForm();
                                mfrm.merchantid = admins.merchant_id;//商户id
                                mfrm.adminid = admins.id;//用户iD
                                this.Form.Show(mfrm);

                                break;
                            case "2":
                                //if (this.Client.Device == "HEY-W09")
                                //{
                                PmainForm pfrm = new PmainForm();
                                pfrm.merchantid = admins.merchant_id;//商户id
                                pfrm.adminid = admins.id;//用户ID
                                pfrm.username = admins.username;//账号
                                pfrm.nickname = admins.nickname;//昵称
                                this.Form.Show(pfrm);
                                //}
                                //else
                                //{
                                //    MessageBox.Show("该设备不支持该类型账号");
                                //}

                                break;
                            case "3":
                                StaffMianForm sfrm = new StaffMianForm();
                                sfrm.merchantid = admins.merchant_id;//商户id
                                sfrm.adminid = admins.id;//用户iD
                                sfrm.nickname = admins.nickname;//姓名
                                this.Form.Show(sfrm);

                                break;
                            case "4":
                                LogForm lfrm = new LogForm();
                                lfrm.merchantid = admins.merchant_id;//商户id
                                lfrm.adminid = admins.id;
                                lfrm.nickname = admins.nickname;
                                this.Form.Show(lfrm);
                                break;
                            case "5":
                                KitchenForm kfrm = new KitchenForm();
                                kfrm.merchantid = admins.merchant_id;//商户id                               
                                this.Form.Show(kfrm);
                                break;
                            case "6":
                                SettlementForm tfrm = new SettlementForm();
                                tfrm.merchantid = admins.merchant_id;//商户id                              
                                
                                this.Form.Show(tfrm);
                                break;
                        }
                        //merchantid = admins.merchant_id;
                        //this.Close();
                    }
                    else
                    {
                        MessageBox.Show("该账号已停用");
                    }
                }
                else
                {
                    MessageBox.Show("账号或密码错误");
                }
            }

        }

        private void LoginForm_KeyDown(object sender, KeyDownEventArgs e)
        {
            if (e.KeyCode == KeyCode.Back)
            {

            }
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {

            if (this.Client.Device == "HEY-W09")
            {

                this.Form.Orientation = Smobiler.Core.Controls.FormOrientation.Landscape;
                this.Form.Direction = LayoutDirection.Row;
                imgbg.Width = 180;
                imgbg.Height = 160;
                imgbg.Location = new System.Drawing.Point(0, 20);
                p2.Width = 300;

            }
        }

        private void LoginForm_OrientationChanged(object sender, OrientationChangedEventArgs e)
        {
            //if (this.Form.Orientation == Smobiler.Core.Controls.FormOrientation.Landscape)
            //{

            //    this.Client.RenderFlush();

            //}
        }
    }
}